package com.example.hello

import android.os.Bundle
import android.view.ViewGroup
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import android.widget.TextView
import android.widget.Button
import android.widget.ImageView
import android.widget.LinearLayout

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        enableEdgeToEdge()
//        setContentView(R.layout.activity_main)
        val linearLayout=LinearLayout(this)
        linearLayout.orientation=LinearLayout.VERTICAL
        val imageview= ImageView(this)
        imageview.setLayoutParams(
            ViewGroup.LayoutParams(
                ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT
            )
        )
        imageview.setImageResource(R.drawable.flag)
        // 将ImageView添加到布局中
        linearLayout.addView(imageview)
        val textView=TextView(this)
        textView.layoutParams=ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT)
        textView.textSize=30F
        textView.text=getString(R.string.textView)
        linearLayout.addView(textView)

        val button =Button(this)
        button.width=ViewGroup.LayoutParams.MATCH_PARENT
        button.height=ViewGroup.LayoutParams.WRAP_CONTENT
        button.text=getString(R.string.button)
        button.textSize=20F
        linearLayout.addView(button)
        setContentView(linearLayout)
        button.setOnClickListener{
            textView.text=resources.getString(R.string.clicked)
        }

    }
}